<!-- 
	轮播图的组件 注意请在父组件里面定义轮播图的大小 下标的样式 和滑动组件的样式  
	在父组件的style 要设置为全局样式，这样样式才可以渲染到轮播图,为了避免污染全局，请给该插件创建一个父级div，并保证class唯一性，如果一个页面有多个轮播图，请保证data-target锚点值得唯一性。
 -->
 
<template>
	<div  class="slider">
	        <div id="myCarousel" class="carousel slide oneCarousel">
			  <ol class="carousel-indicators banner-carousel">
			    <li data-target="#myCarousel" v-for="(item,index) in sliderList" :index="index" :data-slide-to="index" class="active"></li>
			  </ol>
			  <div class="carousel-inner">
			    <a  class="item"  @click="gameStart(item.conGamesoft.softName,item.elementName,item.conGamesoft.softId)" :class="{active:index===0}"  v-for="(item,index) in sliderList" >
			    	<img :src="item.poster?item.poster:'https://app.caizhanbao.cn/detault/2.png'" alt=""/>
			    </a>		    
			  </div>
		  <a  class="carousel-control left" href="#myCarousel" data-slide="prev"></a>
		  <a  class="carousel-control right" href="#myCarousel" data-slide="next"></a>
		</div>
	
	    </div> 
</template>
<style scoped lang="less">


</style>

<script type="text/javascript">
import reportEvent from "../components/report.js"
import $store from "../components/vuex.js"
import axios from 'axios';
	export default{

		
		data(){
			return{
					gameurl:"http://pitf.vgs.lenovo.com.cn",
            		token:"",
			}
		},
		mounted(){
			this.sliderInit()
			
		
		},
		
		props:["className","sliderList","switchImg"],

		methods:{

          
			sliderInit:function(){
				$('.oneCarousel').carousel({
				  interval: 2000,
				  
				})
			},


        //开始游戏
        gameStart(cpId, gameName, softId, serverId, serviceName) { //  cpId 游戏名称  softId   gameId  区服id，区服名
            console.log()
            let that = this;
            var url = `${this.gameurl}/gameRedirect/loginGame?cp=${cpId}_GAME&game=${softId}&gameName=${gameName}&token=${window.sessionStorage.getItem("token")}`


            this.saveGame(window.sessionStorage.getItem("lenovoId"), cpId, softId, 48, serverId, serviceName, gameName)
            window.open(url)
            reportEvent.pageStartGame(this.userId)
        },
        saveGame(lenovoId, cpId, softId, relativeId, serverId, serviceName, gameName) { // 记录玩过的游戏 联想ID cpId softId  平台编号 区服id 区服名 游戏名
            let that = this;
            if (serverId && serviceName) {
                this.resSaveGame(lenovoId, cpId, softId, relativeId, serverId, serviceName, gameName)
            } else {
                console.log(softId)
                let _url = this.gmConf.domainHttps + "unionlogin.4366.com/lenovo/gamecenter/gslist.do?jsonp&serverType=GENERAL&order=opentime:dasc&gsPageSize=5&online" + "&game=" + softId + "&gsPageNo=1"
                console.log(_url)
                that.jqajax(_url, { type: "post", dataType: "jsonp" }, function(res) {

                    var _servers = res[softId].servers;
                    var arr = []
                    for (var item in _servers) {
                        arr.push(_servers[item]);
                    }
                    that.newService = arr[0]
                    console.log(that.newService)

                    that.resSaveGame(lenovoId, cpId, softId, relativeId, that.newService.id, that.newService.name, gameName)

                });
            }

        },
        resSaveGame(lenovoId, cpId, softId, relativeId, serverId, serviceName, gameName) {
            let that = this
            let url = `/gift/api/webpagegame/collectionGame.do?lenovoId=${lenovoId}&relativeId=${relativeId}&serverId=${serverId}&softId=${softId}&serverName=${serviceName}&gameName=${gameName}&softName=${cpId}`;
            axios.get(url).then(function(res) {
                if (res.data.code == 0) {

                } else {
                    that.$toast.center("请求错误")
                }

            }, function(err) {

            })

        },
		}
	}
</script>